<template>
  <div>
    <el-avatar :size="size" :src="imgUrl"/>
  </div>
</template>
<script>
import defaultImg from '@/assets/img/default.jpeg';
import formUtils from '@/utils/formUtils';
import bus from '@/components/common/bus';
export default {
    name: "FancyUserAvatar",
    props:{
      size: {
        type: Number,
        default:50
      }
    },
    data() {
        return {
           imgUrl:''
        }
    },
    created() {
      this.getUserImg();
      bus.$on('userImg', msg => {
        this.getUserImg();
      })
    },
    methods: {
      getUserImg() {
        this.$fetchImg('/api/sys/org/sys_org_person/getUserImg').then(response => {
        　　return btoa(
        　　　　new Uint8Array(response).reduce((data, byte) => data + String.fromCharCode(byte), '')
        　　);
        }).then(data => {
          this.imgUrl = formUtils.isNotEmpty(data)?'data:image/png;base64,' + data : defaultImg;
        })
      }
    }
}
</script>